<template>
  <basic-container v-loading="saveLoading">
    <div style="width:100%;min-height: 50px;padding-left:5px;display: inline-block;">
      <el-container>
        <el-container>
          <el-aside width="100px">
            <el-button type="primary" @click="handlePrint" style="float: left;">打印</el-button>
          </el-aside>
        </el-container>
      </el-container>
    </div>
    <template>
      <div id="printDetail">
          <div style="background:#fff;height: 50px;line-height: 50px;margin-bottom: 10px">
            <div class="pull-auto"  style="text-align: left;font-size: 16px;color:#3478f5;margin-right:10px">
              <div class="block">
                产线名称：{{lineName}}
              </div>
            </div>
          </div>
          <div class="form-designer">
            <el-container style="border: #e0e0e0 solid 1px;border-top:none">
              <el-main class="demo">
                <avue-flow :height="800"
                           width="100%"
                           ref="flow"
                           :option="option"
                           v-model="flowForm">
                  <template #header="{node}" >
                    {{(node || {}).name}}
                  </template>
                  <template slot-scope="{node}">
                    <el-descriptions  class="margin-top"  style="width: 100%;" title="" :column="1" size="small" border >
                      <el-descriptions-item label="工段">
                        <span>{{form[node.id+`_workshopSection`]}}</span>
                      </el-descriptions-item>
                    </el-descriptions>
                  </template>
                </avue-flow>

              </el-main>
            </el-container>
          </div>
      </div>
    </template>
  </basic-container>
</template>

<script>
    import {getPfocProcessList } from '@/api/pfoc/pfocprocess'
    import {getObj} from '@/api/pfoc/realityproductlinetemplate'

    export default {
        name: "view-line-tpl",
        props:{
            lineId:{//产线ID
                type:String
            },
        },
        data() {
            return {
                count: 0,
                nodeCount:0,//节点下标
                form: [],//提交时数据集合
                flowForm:'',
                pfocProcessList:[],//工序集合
                option: {
                    name: null,
                    nodeList: [],//工序节点集合
                    lineList: [],//工序各节点指向顺序集合
                },
                lineName:null,//产线名称
                saveLoading:false,//保存时遮罩开关
            };
        },
        created() {
            //获取工序
            this.getPfocProcessListData();
        },
        computed: {
            nodeList () {
                return this.option.nodeList
            }

        },
        mounted() {
            this.nodeCount = this.option.nodeList.length;//初始化节点下标
        },
        methods: {
            getRealityProductLineTpl(){
                if(!this.validatenull(this.lineId)) {
                    getObj(this.lineId).then(response => {
                        this.$refs.flow.resetPlumb();
                        var data =response.data.data;
                        //产线模板名称
                        this.lineName =data.lineName;
                        //设置反显工序
                        this.option.nodeList = JSON.parse(data.processNodes);
                        //设置反显工序指向顺序
                        this.option.lineList =  JSON.parse(data.processNodeLine);
                        //初始化节点下标
                        var n =  this.option.nodeList[ this.option.nodeList.length-1].id;
                        this.nodeCount = parseInt(n.split("node")[1])+1;

                        //显示各个工序所属工段
                        for (var i = 0; i < this.option.nodeList.length; i++) {
                            var nodeId = this.option.nodeList[i].id;
                            for(var j = 0;j< this.pfocProcessList.length;j++){
                                if( this.pfocProcessList[j].id == this.option.nodeList[i].mark){
                                    this.$set(this.form, nodeId + "_workshopSection",this.pfocProcessList[j].workshopSection);//注册动态节点-工段
                                }
                            }
                        }
                        //重新初始化flow组件
                        this.$refs.flow.init();
                    }).catch(() => {
                        this.saveLoading = false
                    })
                }
            },
            /**获取工序*/
            getPfocProcessListData(){
                getPfocProcessList().then(response => {
                    this.pfocProcessList=response.data.data;
                    //显示各个工序所属工段
                    for (var i = 0; i < this.option.nodeList.length; i++) {
                        var nodeId = this.option.nodeList[i].id;
                        for(var j = 0;j< this.pfocProcessList.length;j++){
                            if( this.pfocProcessList[j].id == this.option.nodeList[i].mark){
                                this.$set(this.form, nodeId + "_workshopSection",this.pfocProcessList[j].workshopSection);//注册动态节点-工段
                            }
                        }
                    }
                })

            },
            //打印
            handlePrint () {
                this.$Print('#printDetail');
            },
        }
    };
</script>

<style scoped>
  /deep/.avue-flow__node{
    height: auto!important;
  }
  /deep/ .avue-flow__node-header {
    line-height: 30px;
  }
  /deep/.el-descriptions__title {
    font-size: 14px;
    font-weight: 400;
    margin-top: 5px;
  }



  /*以下样式是打印的时候avue表格错乱修正方式（主要是序号列和操作列固定影响的）*/
  /deep/.el-table__fixed{
    display: none!important;
  }
  /deep/.el-table__fixed-right{
    display: none!important;
  }
  /deep/.el-table__cell.is-hidden>*{visibility:visible !important;}

  /deep/ .avue-grid{
    display: none!important;
  }
  /deep/.el-main{
    background:#fff !important;
  }
  /deep/.el-card__body{
    padding: 0px!important;
  }
  /*去掉滚动条样式*/
  .demo::-webkit-scrollbar {
    display: none; /* Chrome Safari */
  }
  .demo {
    scrollbar-width: none; /* firefox */
    -ms-overflow-style: none; /* IE 10+ */
    overflow-x: hidden;
    overflow-y: auto;
  }
</style>
